use chumsky::Parser;
use matlab_parser::parser::lexer::lexer;
use std::env;
use std::fs;

fn main() {
    let args: Vec<String> = env::args().collect();

    if args.len() != 2 {
        println!("Usage: cargo run --example basic_usage -- <file.m>");
        return;
    }

    let file_path = &args[1];

    match fs::read_to_string(file_path) {
        Ok(code) => {
            println!("--- Parsing MATLAB Code ---");
            println!("{}", code);
            println!("---------------------------\n");

            match lexer().parse(&code).into_result() {
                Ok(ast) => {
                    println!("--- Success: lexer Generated ---");
                    // Using debug print for a detailed view of the AST
                    println!("{:#?}", ast);
                }
                Err(e) => {
                    println!("--- Error: Parsing Failed ---");
                    eprintln!("{:?}", e);
                }
            }
        }
        Err(e) => {
            eprintln!("Error reading file '{}': {}", file_path, e);
        }
    }
}
